package com.thinkgem.jeesite.modules.qy.api;

import com.thinkgem.jeesite.common.utils.EhCacheUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.qy.dto.VideoDto;
import com.thinkgem.jeesite.modules.qy.entity.QyProgram;
import com.thinkgem.jeesite.modules.qy.entity.QyUser;
import com.thinkgem.jeesite.modules.qy.service.QyProgramService;
import com.thinkgem.jeesite.modules.qy.service.QyUserService;
import com.thinkgem.jeesite.modules.qy.utils.VuthCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.*;

/**
 * Created by JohnShen on 2016/12/1.
 * 平台用户工具
 */
@RestController
@RequestMapping(value = "front/program")
public class ProgramApi extends BaseController{
        public static final String LIVE_PATH =
                "http://114.215.111.75:5080/live/flash.jsp?host=114.215.111.75&stream=";
        protected Logger logger = LoggerFactory.getLogger(getClass());

        @Autowired
        private QyUserService qyUserService;

        @Autowired
        private QyProgramService programService ;

    //发送验证码
    @RequestMapping(value = "insert")
    @ResponseBody
    public LinkedHashMap<String, Object> addProgram (@Valid QyProgram program , BindingResult br ,
                 HttpServletRequest request , HttpServletResponse response   ){
        LinkedHashMap<String,Object> map = new LinkedHashMap<String,Object>();
        map.put("code",false);
        List<FieldError> errors = br.getFieldErrors();
        if(errors != null && !errors.isEmpty()){
            map.put("errMessage", errors.get(0).getDefaultMessage());
        }else{

            program.setStatus("1");
            program.setStartTime(new Date());
            program.setLivePath(LIVE_PATH+program.getQyuserId());
            programService.save(program);
            map.put("code",true);
        }
        return map;
    }

    @RequestMapping(value = "search")
    public List <VideoDto>  searchVideo(){
        List <VideoDto> list = new ArrayList<VideoDto>();
        //第一个视频
        VideoDto video = new VideoDto();
        video.setImageUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/onetwothree.jpg");
        video.setName("android项目演示和原理讲解");
        video.setVideoUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/myone.mp4");
        //第二个视频
        VideoDto video1 = new VideoDto();
        video1.setImageUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/onetwothree.jpg");
        video1.setName("androidContentObserver 类讲解");
        video1.setVideoUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/mytwo.mp4");
        //第三个视频
        VideoDto video2 = new VideoDto();
        video2.setImageUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/onetwothree.jpg");
        video2.setName("android绘图");
        video2.setVideoUrl("http://johnshen.oss-cn-shanghai.aliyuncs.com/mythree.mp4");

        list.add(video);
        list.add(video1);
        list.add(video2);
        return list;
    }
}
